<?php
// install/step3.php

$db_host = $_REQUEST['db_host'] ?? 'localhost';
$db_user = $_REQUEST['db_user'] ?? 'root';
$db_pass = $_REQUEST['db_pass'] ?? 'root';
$db_name = $_REQUEST['db_name'] ?? 'test';

$config_content  = "APP_DEBUG = 1\n\n";
$config_content .= "[APP]\n";
$config_content .= "DEFAULT_TIMEZONE = Asia/Shanghai\n\n";
$config_content .= "[DATABASE]\n";
$config_content .= "TYPE = mysql\n";
$config_content .= "HOSTNAME = $db_host\n";
$config_content .= "USERNAME = $db_user\n";
$config_content .= "DATABASE = $db_name\n";
$config_content .= "PASSWORD = $db_pass\n";
$config_content .= "HOSTPORT = 3306\n";
$config_content .= "CHARSET = utf8\n";
$config_content .= "DEBUG = true\n\n";
$config_content .= "[LANG]\n";
$config_content .= "default_lang = zh-cn\n";


// 写入配置文件
$config_file = '../.env.php';

if (file_put_contents($config_file, $config_content) === false) {
    die("无法写入配置文件！请确保有写入权限。<a href='step2.php'>返回</a>");
}

// 创建安装锁文件（防止重复安装）
file_put_contents('../installed.lock', '1');

echo "安装成功！<br/>";
echo "配置文件已生成，网站可以正常使用了。<br/>";
echo "<a href='../index.php'>访问网站首页</a>";
?>